package com.bridgeintelligent.tag.customer.looklike;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Api(tags = "相似客群导出服务接口")
@AllArgsConstructor
@RestController
@RequestMapping("/api/lookLikeExport")
@Slf4j
public class LookLikeExportController {

    private ILookLikeExportService lookLikeExportService;

    @ApiOperation("lookLike新增导出下载")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "set", value = "相似客群导出信息")
    })
    @PostMapping("/addExport")
    public LookLikeResp addExport(@RequestBody LookLikeExportSet set) {
        try {
            //校验相似客群名是否重复
            boolean flag = lookLikeExportService.checkName(set.getExportName());
            if ( flag ){
                return LookLikeResp.error("导出名称重复，请修改导出名称后重新提交！");
            }
            lookLikeExportService.addLookLikeExport(set);
            return LookLikeResp.ok();
        } catch (Exception e) {
            log.error("lookLike新增导出下载信息失败：{}:",e);
            return LookLikeResp.error("lookLike新增导出下载信息失败");
        }
    }

    @ApiOperation("lookLike查看导出信息")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "导出ID")
    })
    @GetMapping("/findById")
    public LookLikeResp findById(String id) {
        try {
            LookLikeExportSet data = lookLikeExportService.findById(id);
            return LookLikeResp.ok(data);
        }catch (Exception e){
            log.error("lookLike查看导出信息失败：{}:",e);
            return LookLikeResp.error("lookLike查看导出信息");
        }
    }

    @ApiOperation("lookLike导出重试")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "导出ID",required = true)})
    @GetMapping("/retry")
    public LookLikeResp retry(String id) {
        try {
            boolean retry = lookLikeExportService.retry(id);
            if (retry){
                return LookLikeResp.ok();
            }else {
                return LookLikeResp.error("重试失败");
            }
        }catch (Exception e){
            log.error("lookLike导出重试失败：{}:",e);
            return LookLikeResp.error("lookLike导出重试失败");
        }
    }

}